package com.goods.controller.business;

import com.goods.business.service.SupplierServices;
import com.goods.common.error.BusinessException;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：MJS
 * @date ：Created in 2021/6/8  11:36
 * @description：TODO
 */
@Api(tags = "业务管理-物资来源")
@RestController
@RequestMapping("/business/supplier")
public class SupplierController {
    @Autowired(required = false)
    private SupplierServices materialServices;
    //查询全部物资来源
    @ApiOperation(value = "物资来源列表", notes = "模糊查询物资来源列表")
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<SupplierVO>> findSupplierList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "pageSize",defaultValue = "6") Integer pageSize,
                                                             SupplierVO supplierVO){
        PageVO<SupplierVO>materialServicesProductList=materialServices.findSupplierList(pageNum,pageSize,supplierVO);
        return ResponseBean.success(materialServicesProductList);
    }
    //添加物资来源
    @ApiOperation(value = "添加物资来源", notes = "添加物资来源信息")
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        materialServices.add(supplierVO);
        return ResponseBean.success();
    }
    //物资来源回显
    @ApiOperation(value = "编辑物资来源", notes = "获取物资来源的详情，编辑物资来源信息")
    @GetMapping("/edit/{id}")
    public ResponseBean<SupplierVO>edit(@PathVariable Long id) throws BusinessException {
        SupplierVO supplierVO=materialServices.edit(id);
        return ResponseBean.success(supplierVO);
    }
    //修改物资来源信息
    @ApiOperation(value = "更新物资来源", notes = "更新物资来源信息")
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,
                               @RequestBody SupplierVO supplierVO){
        materialServices.update(id,supplierVO);
        return ResponseBean.success();
    }
    //删除物资来源
    @ApiOperation(value = "删除物资来源", notes = "删除物资来源信息")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        materialServices.delete(id);
        return ResponseBean.success();
    }

    //查询全部数据
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<SupplierVO>supplierVOList =materialServices.findAll();
        return ResponseBean.success(supplierVOList);
    }
}
